package leetcode;

public class Day4 {
    /*
    * 回文
    * */
    public String longestPalindrome(String s) {
        int len=0;
        int begin=0;
        int i=0;
       for (;i<s.length();i++){
           for (int j=i+1;j<s.length();j++){
               String l=s.substring(i,j+1);
               int curlen=j-i+1;
               if(ishuiwen(l)&&curlen>len){
                    len=curlen;
                    begin=i;
               }
           }
       }
       return s.substring(i,i+len);
    }

    private Boolean ishuiwen(String s) {
        int l=0;
        int r=s.length();
        while (l<=r){
            if(s.charAt(l)!=s.charAt(r)){
                return false ;
            }
            l++;
            r--;
        }
        return true;
    }
    public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
    public ListNode reverseList(ListNode head) {
        if (head==null||head.next==null){
            return head;
        }
        ListNode node=head.next;
        head.next=null;
        while (node!=null){
            ListNode curNext=node.next;
            node.next=head;
            head=node;
            node=curNext;
        }
        return head;
    }
}
